import request from "@/util/request"
import type { Page } from "../common/types"
import type { Ingredients, IngredientsSearchParam } from "./types"

const api: string = "/dishes-service/ingredients"

export const getIngredientsList = (pageNum: number, pageSize: number, form: IngredientsSearchParam) => {
    return request<Page<Ingredients>, Page<Ingredients>>({
        url: api + '/list',
        method: "get",
        params: {
            pageNum,
            pageSize,
            ...form
        }
    })
}

export const addIngredients = (form: Ingredients) => {
    return request<any, any, Ingredients>({
        url: api,
        method: "post",
        data: form
    })
}

export const updateIngredients = (form: Ingredients) => {
    return request<any, any, Ingredients>({
        url: api + `/${form.id}`,
        method: "put",
        data: form
    })
}

export const deleteIngredients = (id: number) => {
    return request<any, any>({
        url: api + `/${id}`,
        method: "delete"
    })
}

export const getIngredientListByType = (type: string | number) => {
    return request<Ingredients[],Ingredients[]>({
        url: api + '/listByType?type=' + type,
        method: 'get'
    })
}